﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Reflection;

namespace DoveyAttribute.EnumExtend
{
    public static class AttributeExtend
    {
        public static string GetRemark(this Enum value)
        {
            Type type = value.GetType();
            var field = type.GetField(value.ToString());
            if(field.IsDefined(typeof(RemarkAttribute),true))
            {
                //RemarkAttribute attribute = (RemarkAttribute)field.GetCustomAttributes(typeof(RemarkAttribute),false).FirstOrDefault();
                //return attribute._Remark;
                RemarkAttribute attribute = (RemarkAttribute)field.GetCustomAttribute(typeof(RemarkAttribute), true);
                return attribute._Remark;
            }
            return value.ToString();
        }
           
    }
}
